home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_plistlib.py < prev    next >
Text File  |  2005-11-19  |  2KB  |  76 lines

  1. # Copyright (C) 2003 Python Software Foundation
  2.  
  3. import unittest
  4. import plistlib
  5. import os
  6. from test import test_support
  7.  
  8. class TestPlistlib(unittest.TestCase):
  9.  
  10.     def tearDown(self):
  11.         try:
  12.             os.unlink(test_support.TESTFN)
  13.         except:
  14.             pass
  15.  
  16.     def _create(self):
  17.         pl = plistlib.Plist(
  18.             aString="Doodah",
  19.             aList=["A", "B", 12, 32.1, [1, 2, 3]],
  20.             aFloat = 0.1,
  21.             anInt = 728,
  22.             aDict=plistlib.Dict(
  23.                 anotherString="<hello & hi there!>",
  24.                 aUnicodeValue=u'M\xe4ssig, Ma\xdf',
  25.                 aTrueValue=True,
  26.                 aFalseValue=False,
  27.             ),
  28.             someData = plistlib.Data("<binary gunk>"),
  29.             someMoreData = plistlib.Data("<lots of binary gunk>" * 10),
  30.         )
  31.         pl['anotherInt'] = 42
  32.         try:
  33.             from xml.utils.iso8601 import parse
  34.             import time
  35.         except ImportError:
  36.             pass
  37.         else:
  38.             pl['aDate'] = plistlib.Date(time.mktime(time.gmtime()))
  39.         return pl
  40.  
  41.     def test_create(self):
  42.         pl = self._create()
  43.         self.assertEqual(pl["aString"], "Doodah")
  44.         self.assertEqual(pl["aDict"]["aFalseValue"], False)
  45.  
  46.     def test_io(self):
  47.         pl = self._create()
  48.         pl.write(test_support.TESTFN)
  49.         pl2 = plistlib.Plist.fromFile(test_support.TESTFN)
  50.         self.assertEqual(dict(pl), dict(pl2))
  51.  
  52.     def test_stringio(self):
  53.         from StringIO import StringIO
  54.         f = StringIO()
  55.         pl = self._create()
  56.         pl.write(f)
  57.         pl2 = plistlib.Plist.fromFile(StringIO(f.getvalue()))
  58.         self.assertEqual(dict(pl), dict(pl2))
  59.  
  60.     def test_cstringio(self):
  61.         from cStringIO import StringIO
  62.         f = StringIO()
  63.         pl = self._create()
  64.         pl.write(f)
  65.         pl2 = plistlib.Plist.fromFile(StringIO(f.getvalue()))
  66.         self.assertEqual(dict(pl), dict(pl2))
  67.  
  68.  
  69.  
  70. def test_main():
  71.     test_support.run_unittest(TestPlistlib)
  72.  
  73.  
  74. if __name__ == '__main__':
  75.     test_main()
  76.